// pages/index/index.js
const app = getApp();
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		location: '',
		marginTop: '',
		navTop: '',
		capsuleHeight: '',
		// 分页参数
		condition: {
			excludeTags: 'internal',
			includeTags: 'theme',
			max: 12,
			offset: 0,
			tags: 'Theme',
		},
		swiperList: [
			{
				id: 1,
				imageUrl: 'https://dl.zhutix.net/2023/05/ai-jqr-002.jpg',
			},
			{
				id: 2,
				imageUrl: 'https://dl.zhutix.net/2023/05/aerial-boat-photography-02.jpg',
			},
			{
				id: 3,
				imageUrl: 'https://dl.zhutix.net/2023/05/huanghun-jie-02.jpg',
			},
		],
		current: 0,
		list: [],
		imageList: [
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/ai-jqr-002.jpg',
				contents: 'AI机器人',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/aerial-boat-photography-02.jpg',
				contents: '无人机航拍',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/huanghun-jie-02.jpg',
				contents: '黄鹤楼',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/ai-jqr-002.jpg',
				contents: 'AI机器人',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/aerial-boat-photography-02.jpg',
				contents: '无人机航拍',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/huanghun-jie-02.jpg',
				contents: '黄鹤楼',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/aerial-boat-photography-02.jpg',
				contents: '无人机航拍',
				time: '2024-11-10',
			},
			{
				imgUrl: 'https://dl.zhutix.net/2023/05/huanghun-jie-02.jpg',
				contents: '黄鹤楼',
				time: '2024-11-10',
			},
		],
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		const windowInfo = wx.getWindowInfo(); //获取窗口信息
		const menuButtonInfo = wx.getMenuButtonBoundingClientRect(); // 获取菜单按钮（右上角胶囊按钮）的布局位置信息。坐标信息以屏幕左上角为原点
		const navTop = windowInfo.statusBarHeight; // 状态栏的高度，单位px
		// 设置值
		this.setData({
			navTop: menuButtonInfo.top,
			navHeight: menuButtonInfo.height,
		});

		if (!wx.getStorageSync('userInfo')) {
			wx.reLaunch({
				url: '/pages/login/login',
			});
		} else {
			this.getLocation();
			this.getData();
		}
	},
	// 用户点击获取地址
	bindTapGetLocation() {
		// app.utils.showToast('当前接口暂未开放，请稍后再试', 1500, 'error');
		this.setData({
			location: '西安',
		});
	},
	// 自动获取地址
	getLocation() {
		wx.getLocation({
			type: 'wgs84',
			success(res) {
				console.log('res', res);
			},
		});
	},
	// 获取数据
	async getData() {
		let { code, plugins, total } = await app.$http('/searchPlugins', {
			...this.data.condition,
		});
		if (plugins) {
			// https://plugins.jetbrains.com/files/11938/preview_19494.png
			const url = 'https://plugins.jetbrains.com';
			plugins.forEach(item => {
				item.imgUrl = url + item.previewImage;
			});
			// this.setData({
			//   list: [...data.slice(0, 6)],
			// });
		}
	},
	// 点击事件
	handleOnClick(event) {
		const index = app.utils.getConditionParams(event, 'index');
	},
	// 滑动到底部事件
	handleScrolltolower() {
		app.utils.showToast('到底了...');
		this.data.condition.limit += 6;
		this.getData();
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {},

	/**
	 * 用户点击右上角分享
	 */
	onShareTimeline() {
		return {
			title: '刘总小程序',
			query: '',
		};
	},
	onShareAppMessage() {
		return {
			title: '刘总小程序',
			path: '/pages/index/index',
		};
	},
});
